package mr.ali.video.web.controller;


import lombok.extern.slf4j.Slf4j;
import mr.ali.video.web.Exception.R;
import mr.ali.video.web.model.Actor;
import mr.ali.video.web.service.IActorService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Mr-ali
 * @since 2024-09-08
 */
@RestController
@RequestMapping("/web/actor")
@Slf4j
public class ActorController {
   @Resource
   private IActorService actorService;

   @GetMapping("")
   public R<List<Actor>> getAllActor() {
      List<Actor> actorList = actorService.getActorList();
      return R.ok(actorList);
   }


   @GetMapping("/selectById")
   public R<Actor> updateById(Integer id) {
      log.info("video:{}", id);
      Actor video = actorService.getById(id);
      if (video == null) {
         return R.NOT_FOUND("演员不存在");
      }
      return R.ok(video);
   }

   @GetMapping("/selectByText")
   public R<Actor> updateById(String name) {
      log.info("actor:{}", name);
      Actor video = actorService.getActorListByText(name);
      if (video == null) {
         return R.NO_CONTENT("演员不存在");
      }
      return R.ok(video);
   }
   @PostMapping("/update")
   public R<Integer> updateById(Actor video) {
      log.info("video:{}", video);
      Integer row = actorService.updateByAll(video);
      return R.ok(row);
   }


   @PostMapping("/insert")
   public R<Integer> add(Actor t) {
      log.info("videoisert:{}", t);
      Integer row = actorService.insertVideo(t);
      if (row == 0) {
         return R.INTERNAL_SERVER_ERROR("添加失败");
      }
      return R.ok(row);
   }

   @PostMapping("/deleteById")
   public R<Integer> deleteById(Integer id) {
      log.info("id:{}", id);
      Integer row = actorService.deleteById(id);
      if (row == 0) {
         return R.INTERNAL_SERVER_ERROR("删除失败");
      }
      return R.ok(row);
   }


}
